//
//  BeforeWorkListViewController.m
//  TeamInformatization
//
//  Created by bigger on 2019/4/7.
//  Copyright © 2019年 SPIC. All rights reserved.
//

#import "BeforeWorkListViewController.h"
#import "SelectSearchAimView.h"
#import "CommonMessageViewCell.h"
#import "CommonMessage.h"
#import "MeetingData.h"

@interface BeforeWorkListViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *classMeetingTableView;

@property (nonatomic, strong) NSMutableArray *meetingListArray;

@end

@implementation BeforeWorkListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
     [self showTitleBarWithTitle:_vcTitle leftButtonStyle:Base_NavigationBar_Back rightButtonStyle:Base_NavigationBar_None];
    
    // UI
    [self loadShowViews];
    // Data
    NSDictionary * params = @{};
    [self loadListDataWithParams:params];
}

- (void)loadListDataWithParams:(NSDictionary *)params
{
//    [AFNRequest cookGetWithURL:kOrganizationList params:nil success:^(id json) {
//
//        alertWithTitleMeaage(@"访问成功", json[@"text"]);
//
//    } failure:^(NSError *error) {
//
//    }];
    
    NSString *requestUrl;
    switch (_meetType) {
        case 1: {
            requestUrl = kBeforeMeetList;
            break;
        }
        case 2: {
            requestUrl = kBeforeMeetList;
        }
        default: {
            requestUrl = kBeforeMeetList;
            break;
        }
    }
    
    
    
    self.meetingListArray = [NSMutableArray arrayWithCapacity:0];

    [AFNRequest cookPostWithURL:requestUrl params:params  success:^(id json) {
        if ([json[@"success"] intValue] == 1) {
            
            for (NSDictionary *dict in json[@"data"]) {
                
                MeetingData *meetData = [[MeetingData alloc] init];
                [meetData setValuesForKeysWithDictionary:dict];
                [self.meetingListArray addObject:meetData];
            }
            
            [self.classMeetingTableView reloadData];
            
        } else {
            
            alertWithTitleMeaage(@"请求失败", json[@"text"]);
        }

    } failure:^(NSError *error) {

    }];
}

- (void)loadShowViews
{
    SelectSearchAimView *selectView = [[SelectSearchAimView alloc] init];
    [self.view addSubview:selectView];
    [selectView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(kSafeAreaTopHeight);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(kScreenWidth, 60 * kScaleWidth));
    }];
    
    self.classMeetingTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kSafeAreaTopHeight + 60 * kScaleWidth, kScreenWidth, kSecondContentHeight - 60 * kScaleWidth) style:UITableViewStylePlain];
    [_classMeetingTableView registerClass:[CommonMessageViewCell class] forCellReuseIdentifier:@"CommonMessage"];
    _classMeetingTableView.delegate = self;
    _classMeetingTableView.dataSource = self;
    _classMeetingTableView.backgroundColor = [UIColor clearColor];
    _classMeetingTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _classMeetingTableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_classMeetingTableView];
    
}

#pragma mark - TableViewDelegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _meetingListArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 152 * kScaleWidth;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    MeetingData *meetData = [[MeetingData alloc] init];
    if (_meetingListArray.count != 0) {
        meetData = self.meetingListArray[indexPath.row];
    }
    
    
    CommonMessageViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonMessage" forIndexPath:indexPath];
    if (!cell) {
        cell = [[CommonMessageViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CommonMessage"];
    }
    
    [cell setShowCellWithMeetingData:meetData MeetType:_meetType];
    
    return cell;
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}



#pragma -导航栏 两边按钮操作
-(void)baseNavigationBarLeftButtonClick:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
